package itsm.isperp.module.utils;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.data.dialect.DialectFactory;

import org.springframework.jdbc.core.JdbcTemplate;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2015-5-3
 * @since 1.0
 * 
 */
public final class DbQueryUtils {
	public static boolean exists(Class<?> clazz, String column, Object value) {

		String sql = "SELECT id FROM "
				+ clazz.getAnnotation(javax.persistence.Table.class).name()
				+ " WHERE " + column + "=?";

		sql = DialectFactory.getDialect().getLimitString(sql);

		JdbcTemplate jdbcTemplate = ContextHolder.getSpringBean("jdbcTemplate");

		try {
			jdbcTemplate.queryForObject(sql, new String[1], String.class);
			return true;
		} catch (Exception e) {
			return false;
		}

	}
}
